//
//  FZEmoticonPageView.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/30/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit


private let emoticonCellId = "emoticonCellId"

class FZEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: layout)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        dataSource = self
        
        let flowLayout = self.collectionViewLayout as! UICollectionViewFlowLayout
        flowLayout.itemSize = CGSizeMake(SCREENW, 216 - 30)
        flowLayout.scrollDirection = .Horizontal
        flowLayout.minimumLineSpacing = 0
        flowLayout.minimumInteritemSpacing = 0

        registerClass(FZEmoticonPageCell.self, forCellWithReuseIdentifier: emoticonCellId)
    }

    
}

extension FZEmoticonPageView: UICollectionViewDataSource{

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return FZEmoticonTool.sharedTool.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return FZEmoticonTool.sharedTool.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(emoticonCellId, forIndexPath: indexPath) as! FZEmoticonPageCell
        cell.emoticons = FZEmoticonTool.sharedTool.allEmoticons[indexPath.section][indexPath.item]
        return cell
    }
}
